%{
#include <iostream>
using namespace std;
#define YY_DECL extern "C" int yylex()

int line_num = 1;

#include "decaf.parse.h"

%}
%x COMMENTS
letter		[A-Za-z]
digit			[0-9]
id				{letter}({letter}|{digit}|_)*
myeof     <<EOF>>

%%
[ \t]						;
[ \n\r]					{ line_num++; }
\/\/[^\n]*\n		{ line_num++; }

\/\*						{ BEGIN(COMMENTS);}
<COMMENTS>\*\/	{ BEGIN(INITIAL); }
<COMMENTS>\n		{ line_num++; }
<COMMENTS><<EOF>> {return MULTILINE_COMMENT_ERROR;}
<COMMENTS>.			;

boolean 				{ return BOOLEAN; }
break						{ return BREAK; }
continue				{ return CONTINUE; }
class						{ return CLASS; }
do							{ return DO;	}
else						{ return ELSE;	}
extends					{ return EXTENDS; }
false						{ return FALSE; }
float						{ return FLOAT; }
for							{ return FOR; }
if 							{ return IF; }
int 						{ return INT; }
new							{ return NEW; }
null						{ return DECAF_NULL; }
private					{	return PRIVATE; }
public					{ return PUBLIC; }
return					{ return RETURN; }
static					{ return STATIC; }
super						{ return SUPER; }
this						{ return THIS;	}
true						{ return TRUE; }
void						{ return VOID; }
while						{ return WHILE; }	
{id}						{ yylval.sval = strdup(yytext); return ID; }
{digit}+				{ yylval.ival = atoi(yytext); return INT_CONST; }
{digit}+\.(({digit}+)|({digit}*(e|E)[+-]?{digit}+)) { yylval.fval = atof(yytext); return FLOAT_CONST; }
\"([^\\\"]|\\.)*\"  { yylval.sval = strdup(yytext); return STRING_CONST; }
[\(\)\{\};\[\]\+\-\*\/,\.!=><] { return yytext[0]; }
\&\&						{ return B_AND; }
\|\|						{ return B_OR; }
==							{ return B_EQ_TO; }
>=							{ return B_GREATER_THAN_EQ_TO; }
\<\=						{ return B_LESS_THAN_EQ_TO; }
\+\+						{ return PLUS_PLUS; }
\-\-						{ return MINUS_MINUS; }
.								{ cout << "Matched unknown"; return UNKNOWN; } 

%%	
